<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>TodoList</title>
    <script src="../vue.js"></script>
</head>
<body>
<div id="app">
    <input type="text" v-model="inputValue"/>
    <button v-on:click="handleBtnClick">提交</button>
    <ul>
        <todo-item v-bind:content = "item"
                   v-bind:index= "index"
                   v-for = "(item,index) in list"
                   @delete="handleItemDelete"></todo-item>
    </ul>
</div>

<script>
    var TodoItem = {
        props:['content','index'],
        template:"<li @click='handleItemClick'>{{content}}</li>",
        methods:{
            handleItemClick:function () {
                this.$emit("delete",this.index)
            }
        }
    }
    var app = new Vue({
        el:'#app',
        components:{
            TodoItem: TodoItem
        },
        data: {
            list: [],
            inputValue:''
        },
        methods:{
            handleBtnClick: function () {
                this.list.push(this.inputValue)
                this.inputValue = ''
            },
            handleItemDelete: function (index) {
                this.list.splice(index,1)
            }
        }

    })
</script>
</body>
</html>

<!-- v-for:循环数组以便显示 v-on:绑定事件 v-model:双向绑定数据 -->